package com.qf.controller;

import com.qf.service.DtsOrderGoodsService;
import com.qf.service.DtsOrderService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import com.qf.vo.DayCountStatis;
import com.qf.vo.OrderAndUser;
import com.qf.vo.OrderIdAndGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName:workspace_6
 * author:hyn
 * time:2021/11/30 15:56
 * description:统计
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/admin/stata")
public class AdminStatUserController {
    @Autowired
    private DtsUserService userService;
    @RequestMapping("user")
    public Object user(){

        Map<String, Object> data = new HashMap<>();
        //用户统计
        List<DayCountStatis> dayCountStatis = userService.findUserCount(30);

        String [] columns = {"day","users"};

        data.put("columns",columns);
        data.put("rows",dayCountStatis);
        return ResponseUtil.ok(data);
    }
    @Autowired
    private DtsOrderGoodsService orderGoodsService;
    //订单统计
    @RequestMapping("order")
    public Object order(){
        List<OrderAndUser> orderUser = orderGoodsService.findOrderUser(30);
        String [] columns = {"day","orders","customers","amount","pcr"};
        Map<String, Object> data = new HashMap<>();
        data.put("columns",columns);
        data.put("rows",orderUser);
        return ResponseUtil.ok(data);
    }

    //商品统计
    @Autowired
    private DtsOrderService orderService;
    @RequestMapping("goods")
    public Object goods(){
        List<OrderIdAndGoods> goodsAndOrder = orderService.findGoodsAndOrder(30);
        Map<String, Object> data = new HashMap<>();
        String [] columns = {"day","orders","products","amount"};
        data.put("columns",columns);
        data.put("rows",goodsAndOrder);
        return ResponseUtil.ok(data);
    }
}
